package com.company.cloud.club.modules.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.company.cloud.club.modules.core.dto.project.CaseBrandDto;
import com.company.cloud.club.modules.core.dto.project.CaseDto;
import com.company.cloud.club.modules.db.domain.*;
import com.company.cloud.club.modules.dto.product.OrderParam;
import com.company.cloud.club.modules.dto.product.OrderParamDto;
import com.company.cloud.club.modules.dto.project.ProjectDto;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface ProjectCaseMapper extends BaseMapper<ProjectCase> {
    @Select("SELECT * FROM pj_case ORDER BY time_created DESC")
    List<CaseDto> caseList();

    @Select("SELECT * FROM pj_case_brand where case_id=#{id} ORDER BY time_created DESC")
    List<ProjectCaseBrand> selectCaseId(String id);

    @Select("SELECT * FROM pj_case_brand where case_id=#{id} ")
    ProjectCaseBrand selectCaseBrandId(String id);

    @Delete("delete from pj_banner where id=#{id}")
    int Bannerdelete(@Param("id") String id);

    @Select("SELECT * FROM pj_project  where  deleted=0  ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<Project> listPage(@Param("currentPage") Integer currentPage,
                           @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_project  where  deleted=0 ORDER BY time_created DESC  ")
    int proCount();

    @Select(" SELECT * FROM pj_case_brand where case_id=#{caseId} ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<ProjectCaseBrand> CaseListPage(@Param("caseId") String caseId, @Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_case_brand where case_id=#{caseId} ORDER BY time_created DESC ")
    int CaseListCount(@Param("caseId") String caseId);

    @Delete("delete from pj_case_brand where id=#{id}")
    int caseDelete(String id);

    @Select(" SELECT * FROM pj_project_apply ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<ProjectApply> ApplyListPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_project_apply ORDER BY time_created DESC ")
    int ApplyListCount();


    @Delete("delete from pj_project_apply where id=#{id}")
    int ApplyDelete(@Param("id") String id);

    @Update("update  pj_project set deleted=1 where id=#{id}")
    int projectDelete(@Param("id") String id);

    @Select("select * from pj_project_apply where id=#{id}")
    ProjectApply getOne(@Param("id") String id);

    @Update(" update pj_project_apply set mtype=#{mtype}  where id = #{id,jdbcType=VARCHAR}")
    boolean applyUpdate(@Param("mtype") int mtype, @Param("id") String id);


    @Select(" SELECT * FROM pj_project_option ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<ProjectOption> OptionListPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_project_option ORDER BY time_created DESC ")
    int OptionListCount();

    @Select("select * from pj_project_option where id=#{id}")
    ProjectOption getOptionOne(@Param("id") String id);

    @Delete("delete from pj_project_option where id=#{id}")
    int optionDels(@Param("id") String id);

    @Select("select * from pj_project_apply where uid=#{currentUserId}")
    ProjectApply getprijectOne(@Param("currentUserId") Integer currentUserId);

    @Select("select * from pj_project_order where project_id=#{id}")
    ProjectOrder getProjectOrder(@Param("id") String id);

    @Delete("delete from pj_project_order where id=#{id}")
    int orderDel(@Param("id") String id);

    @Select(" SELECT * FROM pj_project_order  where project_id=#{projectId} ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<ProjectOrder> OrderListPage(@Param("projectId") String projectId, @Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_project_order where project_id=#{projectId}  ORDER BY time_created DESC ")
    int OrderListCount(@Param("projectId") String projectId);

    @Select(" SELECT * FROM pj_case  ORDER BY time_created DESC  limit #{currentPage}, #{pageSize}")
    List<ProjectCase> proCaseListPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_case  ORDER BY time_created DESC ")
    int proCaseListCount();

    @Select("select *  from pj_case_brand where case_id=#{caseId}")
    List<ProjectCaseBrand> caseVo(@Param("caseId") String caseId);

    @Delete("delete from pj_case where id=#{id}")
    int caseVoDelete(@Param("id") String id);

    @Select("select * from pj_project where uid=#{currentUserId}")
    List<Project> releaseProject(@Param("currentUserId") Integer currentUserId);

    @Select("select * from pj_project_order where project_id=#{id}")
    List<ProjectOrder> releaseOrder(@Param("id") String id);

    @Select("select * from pj_project_order where uid=#{id}")
    List<ProjectOrder> releaseOrderAll(@Param("id") Integer id);

    @Select("SELECT * FROM pj_message ORDER BY time_created DESC limit #{currentPage}, #{pageSize}")
    List<Message> messagePage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize);

    @Select(" SELECT count(*) FROM pj_message ORDER BY time_created DESC ")
    int messageCount();

    @Delete("delete from pj_message where id=#{id}")
    int messageDel(@Param("id") String id);

    @Select("select  id as id,nick_name as userName, mobile as phone ,user_tags as userTags  from cust_user_info where id=#{id}")
    CustUserInfo CustUser(@Param("id") int id);

    @Update("update  cust_user_info set user_tags=#{token} where id=#{id}")
    int CustUserUpdate(Integer id, String token);

    @Update("update  pj_message set mtype=#{mtype} where id=#{id}")
    int messageUpdate(String id, Integer mtype);



    @Select("select  * from pj_message where uid=#{currentUserId}  ORDER BY time_created DESC ")
    List<Message> getUid (@Param("currentUserId")Integer currentUserId);


    @Select("select * from t_tenant_apply_info where id=#{id}")
    TenantApplyInfo companyApplyById(@Param("id") String id);

    @Select("select  id as id,nick_name as userName,mobile as phone from cust_user_info ORDER BY cdt desc ")
    List<CustUserInfo> CustUserList();


    @Select("select  product_no as productNo,name as productName from prd_product_info ORDER BY cdt desc LIMIT 0,50")
    List<ParameterInfoPamar> ParmsLists();

    @Select("select  product_no as productNo,name as productName from prd_product_info where name LIKE CONCAT('%', #{productName,jdbcType=VARCHAR}, '%') ")
    List<ParameterInfoPamar> ParmsList(@Param("productName") String productName);

    @Delete("delete from t_tenant_apply_info where id=#{id}")

    int companyApplyDel(@Param("id") String id);

    @Select("select  count(*) from pj_message where uid=#{currentUserId} and mtype=0 ORDER BY time_created DESC ")
   int getUidCount (@Param("currentUserId")Integer currentUserId);

    @Select("insert into club_jspatch (vers, url, lost, ctime, utime, dtime, introduce)  values (#{patch.vers,jdbcType=VARCHAR}, #{patch.url,jdbcType=VARCHAR}, #{patch.lost,jdbcType=TIMESTAMP},  #{patch.ctime,jdbcType=TIMESTAMP}, #{patch.utime,jdbcType=TIMESTAMP}, #{patch.dtime,jdbcType=INTEGER}, #{patch.introduce,jdbcType=VARCHAR})")
   void  insertSelective(@Param("patch")jsPatch patch);

    @Select("select id, vers, url, lost, ctime, utime, dtime, introduce FROM club_jspatch order by lost DESC limit 1")
    jsPatch selectOne();

   /* @Insert("INSERT INTO `art_v2`.`mall_order_info`(`sn`, `company_no`, `main_company_no`, `user_id`, `referral_code`, `referral_user_id`, `order_type`, `order_date`, `order_expire`, `fund`, `product_fund`, `order_param`, `status`, `is_exchange_point`, `exchange_point`, `is_reward_point`, `reward_point`, `is_use_coupon_code`, `coupon_code`, `coupon_discount_fund`, `user_memo`, `user_del_state`, `payment_method`, `payment_fee`, `payment_fund`, `payment_state`, `pay_date`, `shipping_method`, `freight`, `consignee_name`, `consignee_phone`, `consignee_province`, `consignee_city`, `consignee_region`, `consignee_street`, `consignee_addr`, `is_invoice`, `invoice_type`, `invoice_title`, `invoice_tax_no`, `invoice_content`, `is_allocated_stock`, `refund_fund`, `check_date`, `shipping_date`, `receiving_date`, `complete_date`, `close_date`, `handle_date`, `handle_user_id`, `handle_memo`, `use_user_name`, `use_user_mobile`, `exchange_code`, `is_dis_product`, `cman`, `eman`, `cdt`, `edt`, `cip`, `eip`, `rows_state`) " +
            "VALUES (#{params.orderNo,jdbcType=VARCHAR}, 'PTC', 'PTC', #{params.userId,jdbcType=VARCHAR}, NULL, NULL, '30', #{params.orderDate,jdbcType=VARCHAR},#{params.orderDate,jdbcType=VARCHAR}, #{params.fund,jdbcType=DECIMAL}, #{params.productFund,jdbcType=DECIMAL}, #{params.orderParam,jdbcType=VARCHAR},#{params.status,jdbcType=VARCHAR}, '', 0, NULL, 0, '', NULL, NULL, NULL, '', NULL, 0.000000, 0.000000, NULL, NULL, NULL, 0.000000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)")
*/    @Insert("INSERT INTO `art_v2`.`mall_order_info`(`sn`, `company_no`, `main_company_no`, `user_id`, `referral_code`, `referral_user_id`, `order_type`, `order_date`, `order_expire`, `fund`, `product_fund`, `order_param`, `status`, `is_exchange_point`, `exchange_point`, `is_reward_point`, `reward_point`, `is_use_coupon_code`, `coupon_code`, `coupon_discount_fund`, `user_memo`, `user_del_state`, `payment_method`, `payment_fee`, `payment_fund`, `payment_state`, `pay_date`, `shipping_method`, `freight`, `consignee_name`, `consignee_phone`, `consignee_province`, `consignee_city`, `consignee_region`, `consignee_street`, `consignee_addr`, `is_invoice`, `invoice_type`, `invoice_title`, `invoice_tax_no`, `invoice_content`, `is_allocated_stock`, `refund_fund`, `check_date`, `shipping_date`, `receiving_date`, `complete_date`, `close_date`, `handle_date`, `handle_user_id`, `handle_memo`, `use_user_name`, `use_user_mobile`, `exchange_code`, `is_dis_product`, `cman`, `eman`, `cdt`, `edt`, `cip`, `eip`, `rows_state`)" +
            " VALUES (#{params.orderNo,jdbcType=VARCHAR}, 'PTC', 'PTC', #{params.userId,jdbcType=VARCHAR}, NULL, NULL, '60', #{params.orderDate,jdbcType=VARCHAR}, #{params.orderDate,jdbcType=VARCHAR}, #{params.fund,jdbcType=DECIMAL},#{params.productFund,jdbcType=DECIMAL}, #{params.orderParam,jdbcType=VARCHAR}, #{params.status,jdbcType=VARCHAR}, '0', 0, '0', 0, '0', NULL, 0.000000, '门票订单', '1', NULL, 0.000000, #{params.paymentFund,jdbcType=DECIMAL}, #{params.paymentState,jdbcType=VARCHAR},, NULL, '60', 0.000000, #{params.consigneeName,jdbcType=VARCHAR},  #{params.consigneePhone,jdbcType=VARCHAR}, NULL, NULL, NULL, NULL, '上海', '0', NULL, NULL, NULL, NULL, '1', 0.000000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '0', NULL, NULL, NULL, NULL, NULL, NULL, NULL);")
    int orderInster(@Param("params") OrderParamDto params);



}